package com.example.stock.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.stock.entity.eo.FundBasicEo;
import com.example.stock.entity.eo.IndexBasicEo;
import com.example.stock.entity.eo.StockBasicEo;
import com.example.stock.entity.mapper.FundBasicMapper;
import com.example.stock.entity.mapper.IndexBasicMapper;
import com.example.stock.entity.mapper.StockBasicMapper;
import com.example.stock.service.IServiceBasic;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class ServiceBasicImpl implements IServiceBasic {

    @Resource
    private StockBasicMapper stockBasicMapper;
    @Resource
    private IndexBasicMapper indexBasicMapper;
    @Resource
    private FundBasicMapper fundBasicMapper;

    public String getName(String tsCode) {
        String name = "";
        IndexBasicEo stockTradeEo = indexBasicMapper.selectOne(Wrappers.query(new IndexBasicEo().setTsCode(tsCode)));
        if (null != stockTradeEo) {
            return stockTradeEo.getName();
        }

        StockBasicEo stockBasicEo = stockBasicMapper.selectOne(Wrappers.query(new StockBasicEo().setTsCode(tsCode)));
        if (null != stockBasicEo) {
            return stockBasicEo.getName();
        }

        FundBasicEo fundBasicEo = fundBasicMapper.selectOne(Wrappers.query(new FundBasicEo().setTsCode(tsCode)));
        if (null != fundBasicEo) {
            return fundBasicEo.getName();
        }


        return name;
    }
}
